package springboot.service.impl;

import org.springframework.stereotype.Service;
import springboot.dao.OverTimeDataDao;
import springboot.doMain.OverTimeData;
import springboot.Tools.Date.StartAndEndTime;
import springboot.service.OverTimeDataService;

import java.util.Calendar;
import java.util.List;
import java.util.Map;

/**
 * wxWork
 * springboot.service.impl
 * Created by Blue on 2021/9/13.
 */
@Service
public class OverTimeDataServiceImpl implements OverTimeDataService {

    final
    OverTimeDataDao overTimeDataDao;

    public OverTimeDataServiceImpl(OverTimeDataDao overTimeDataDao) {
        this.overTimeDataDao = overTimeDataDao;
    }

    @Override
    public int insert(OverTimeData record) {
        return overTimeDataDao.insert(record);
    }

    @Override
    public List<Map<String,Object>> selLastData() {
        Calendar instance = Calendar.getInstance();
        instance.setFirstDayOfWeek(Calendar.MONDAY);
        OverTimeData overTimeData = new OverTimeData();
        long l = StartAndEndTime.getWeek(0, instance.get(Calendar.WEEK_OF_MONTH)).getWeekStartTime().getTime() / 1000;
        overTimeData.setDate(l);
      return overTimeDataDao.selLastDataWeek(overTimeData);
    }

    @Override
    public void insertOverTimeData() {
        OverTimeData.fillList(overTimeDataDao.selOverTimeData()).forEach(overTimeDataDao::insert);
    }

    @Override
    public int insertSelective(OverTimeData record) {
        return 0;
    }
}
